package com.sample.services;

import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener
{
	Service appService;
	Button b1;
	private ServiceConnection onService = new ServiceConnection()
	{
		public void onServiceConnected(ComponentName ServiceTest, IBinder rawBinder)
		{
			appService = ((ServiceTest.LocalBinder)rawBinder).getService();
		}
		public void onServiceDisconnected(ComponentName ServiceTest) 
		{
			appService = null;
		}	
	};
	public void onCreate(Bundle savedInstanceState)
	{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        b1 = (Button)findViewById(R.id.button1);
        bindService(new Intent(this, ServiceTest.class), onService, Context.BIND_AUTO_CREATE);
        b1.setOnClickListener(this);
	}
	public void onClick(View v) 
	{
		appService.startService(new Intent(this, ServiceTest.class));
	}
}